import React, { useRef, useEffect } from "react";
import "./index.less";
import { Button } from "antd";
import { Debounce, queue, throttle, MyPromise,XPromise } from "./utils";
export default function index() {
  const reslist = useRef([]);
  const resData = useRef(0);
  const handleClick = throttle((text) => {
    console.log(text, "------执行了几次");
  }, 1000);

  async function queryData(params) {
    resData.current++;
    return resData.current + params;
  }

  useEffect(() => {
    // getData();
    testPromise();
  }, []);
  function testPromise() {
    new XPromise((resolve, reject) => {
      setTimeout(() => {
        resolve("123");
      }, 2000);
    }).then((res) => {
      console.log(res, "------");
    });
  }

  async function getData() {
    const reqs = {
      params: 5,
      req: queryData,
    };
    const requestList = [reqs, reqs, reqs, reqs, reqs, reqs, reqs];
    const res = await queue(requestList, 4);
    console.log(res, "----");
  }
  function handlePromise() {}
  return (
    <div className="font-box">
      <Button onClick={() => handleClick("hello")}>按钮</Button>
      <Button onClick={() => handlePromise("hello")}>测试promise</Button>
    </div>
  );
}
